<template>
    <el-form :model="form1" :inline="true">
            <el-form-item label="患教活动名称" :label-width="formLabelWidth">
                <el-input v-model="form1.name" autocomplete="off" />
            </el-form-item>
            <el-form-item label="主持人" :label-width="formLabelWidth">
                <el-input v-model="form1.host" autocomplete="off" />
            </el-form-item>
            <el-form-item label="目标人数" :label-width="formLabelWidth">
                <el-input v-model="form1.count" autocomplete="off" />
            </el-form-item>
            <el-form-item label="直播时间" :label-width="formLabelWidth">
                <el-date-picker
                    v-model="form1.liveTime"
                    type="datetime"
                    placeholder="请选择"
                    clearable
                />
            </el-form-item>
            <el-form-item label="报名开始时间" :label-width="formLabelWidth">
                <el-date-picker
                    v-model="form1.signupStartTime"
                    type="datetime"
                    placeholder="请选择"
                    clearable
                    />
            </el-form-item>
            <el-form-item label="报名结束时间" :label-width="formLabelWidth">
                <el-date-picker
                    v-model="form1.signupEndTime"
                    type="datetime"
                    placeholder="请选择"
                    clearable
                    />
            </el-form-item>
            <el-form-item label="患教费用" :label-width="formLabelWidth">
                <el-input v-model="form1.money" autocomplete="off" />
            </el-form-item>
            <el-form-item label="直播持续时间" :label-width="formLabelWidth">
                <el-input :suffix-icon="Timer" v-model="form1.continueTime" autocomplete="off" />
            </el-form-item>
            <el-form-item label="患教说明" :label-width="formLabelWidth">
                <el-input type="textarea" placeholder="请输入患教活动说明" v-model="form1.activityDescription"></el-input>
            </el-form-item>
        </el-form>
</template>

<script setup>
import {ref, onMounted, defineProps, defineEmits, watch} from 'vue'
import { Timer } from '@element-plus/icons-vue'
import { addActivity, getActivityById } from '@/api/patient/patient'
import { ElMessage } from 'element-plus'


const emit = defineEmits(['callBack', 'activityValue']);
const props = defineProps({
    data: {
        type: Number,
        default: 1
    },
    id: {
        type: Number,
    }
})
const dialogVisible = ref(false)
const formLabelWidth = '100px'
//修改时传给后端的数据
const form1 = ref({
    id: props.id,
    name: '',
    host: '',
    liveTime: '',
    signupStartTime: '',
    signupEndTime: '',
    money: '',
    continueTime: '',
    activityDescription: '',
})



watch(()=>form1.value, (newValue,oldValue)=>{
    emit('activityValue', form1.value)
}, {
  deep: true, // 深度监听
})
//根据id查询患教活动
const getPatientById = (id) => {
    getActivityById(id).then((res) => {
        if(res.code == 200){
           
            // console.log(form1.name)
            // console.log(res.data)
            form1.value = res.data
        }
    })
}
//向子组件传值
const tickCallBack = () => {
  emit('callBack', dialogVisible.value);
  console.log("传值给父组件");
};

onMounted(() => {
    // console.log("props.id*************")
    // console.log(props.id)
    if(props.data === 0){
        getPatientById(props.id)
    }
})
</script>

<style lang="scss" scoped>

:deep(.el-input){
    width: 200px;
}
:deep(.el-textarea){
    width: 500px;
    .el-textarea__inner{
        height: 100px !important;
    }
    
}
</style>